import { _decorator, assetManager, Component, ImageAsset, Label, Node, Sprite, SpriteFrame, Texture2D } from 'cc';
import { rankData } from './Rank';
import { Tools } from '../tools/Tools';
const { ccclass, property } = _decorator;

@ccclass('RankNormalItem')
export class RankNormalItem extends Component {
    @property(Sprite)
    mSpIcon: Sprite = null;
    @property(SpriteFrame)
    mDefultSpf: SpriteFrame = null;
    start() {

    }
    InitItem(data: rankData, index: number) {
        let node = this.node;
        node.active = true;
        node.getChildByName("ranNum").getComponent(Label).string = (index + 1) + "";
        node.getChildByName("honorNum").getComponent(Label).string = Tools.FormatNumber(data.honor);
        node.getChildByName("name").getComponent(Label).string = data.nickName;
        if (data.headImg != "") {
            assetManager.loadRemote(data.headImg, { ext: '.png' }, (error, img: ImageAsset) => {
                if (!this.mSpIcon) return;
                const texture = new Texture2D();
                texture.image = img;
                let spFrame = new SpriteFrame();
                spFrame.texture = texture;
                this.mSpIcon.spriteFrame = spFrame;
            }
            )
        } else {
            this.mSpIcon.spriteFrame = this.mDefultSpf;
        }
    }
}


